#include "effectbase.h"
#include "stringproperty.h"
#include "datatypedefine.h"
#include "map.h"

namespace VrDataCore
{
	EffectBase::EffectBase():_bindingMeshDrawableActor(NULL)
	{
		_effect_idle = true ;
		setClassName(CLASS_EFFECT_BASE);
	}

	EffectBase::~EffectBase()
	{}

	void EffectBase::buildPropertyMap()
	{
		addProperty(new StringProperty<EffectBase>(XML_ELEMENT_DATATYPE_STRING,
			"BindingMeshDrawableActorId","",this,&EffectBase::setBindingActorId,
			&EffectBase::getBindingActorId,"",""));
	}

	bool EffectBase::isIdle() 
	{
		return _effect_idle ;
	}

	void EffectBase::reset() 
	{
		_effect_idle = true ;
	}  

	void EffectBase::apply(CoreBase::ActorBase* actor)
	{
		_effect_idle = false ;
		_bindingMeshDrawableActor = actor;
	} 

	void EffectBase::unApply(CoreBase::ActorBase* actor)
	{
		_effect_idle = true ;
	}

	void EffectBase::onMapLoadEnd(CoreBase::Map* map)
	{
		CoreBase::ActorBase* actor = map->getActorById(_bindingMeshDrawableActorId);
		if(actor)
		{
			bindingMeshDrawableActor(actor);
		}
	}

	void EffectBase::setBindingActorId(QString id)
	{
		_bindingMeshDrawableActorId = id;
	}

	QString EffectBase::getBindingActorId()
	{
		if(_bindingMeshDrawableActor!=NULL)
			_bindingMeshDrawableActorId = _bindingMeshDrawableActor->getId();
		return _bindingMeshDrawableActorId;
	}

	void EffectBase::bindingMeshDrawableActor(CoreBase::ActorBase* bindingactor)
	{
		_bindingMeshDrawableActor = bindingactor;
	}

	void EffectBase::removeBindingMeshDrawableActor(CoreBase::ActorBase* bindingactor)
	{
		_bindingMeshDrawableActor = NULL;
	}

	CoreBase::ActorBase* EffectBase::getBindingMeshDrawableActor()
	{
		return _bindingMeshDrawableActor;
	}

	osg::ref_ptr<CoreBase::ActorBase> EffectBase::clone()
	{
		osg::ref_ptr<CoreBase::ActorBase> clone = NoTransformActor::clone();
		return clone;
	}
}